package com.insta.adapterList;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.insta.playdroid.R;
import com.insta.playdroid.metier.domain.Playlist;

public class PlaylistAdapter extends BaseAdapter {

	private List<Playlist> playlists = new ArrayList<Playlist>();
	private LayoutInflater layoutInflater;

	public PlaylistAdapter(Context context, List<Playlist> allPlay) {

		layoutInflater = LayoutInflater.from(context);

		this.playlists = allPlay;
	}

	private class ViewHolder {

		TextView playlisttxt;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;

		if (convertView == null) {

			holder = new ViewHolder();

			convertView = layoutInflater.inflate(R.layout.playlistitem, null);

			holder.playlisttxt = (TextView) convertView
					.findViewById(R.id.itemplay);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();

		}

		holder.playlisttxt.setText(playlists.get(position).getNom());

		return convertView;
	}

	@Override
	public int getCount() {
		return playlists.size();
	}

	@Override
	public Object getItem(int pos) {
		return playlists.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		return pos;
	}

	public List<Playlist> getPlaylists() {
		return playlists;
	}

	public void setPlaylists(List<Playlist> plays) {
		this.playlists = plays;
	}

	public LayoutInflater getLayoutInflater() {
		return layoutInflater;
	}

	public void setLayoutInflater(LayoutInflater layoutInflater) {
		this.layoutInflater = layoutInflater;
	}
}
